package dao;

import domain.Orders;
import domain.Type;
import util.DbUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TypeDao {
    DbUtil dbUtil = new DbUtil();
    public List<Type> findAllOrder(){
        String sql = "select * from type";
        System.out.println(sql);
        ResultSet rs = dbUtil.executeQuery(sql);
        List<Type> list = new ArrayList<Type>();
        try {
            while (rs.next()){
                Type t = converToType(rs);
                list.add(t);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
        return list;
    }

    public Type converToType(ResultSet rs){
        Type t = null;
        try{
            int typeid = rs.getInt(1);
            String typename = rs.getString(2);
            t = new Type(typeid, typename);
            return t;
        }catch (SQLException e){
            e.printStackTrace();
            return null;
        }
    }

}
